package com.ideal.gpt.ability.docqa.splitter;

import java.util.ArrayList;
import java.util.List;

import com.lzwork.utility.pair.StringPair;

/**
 * @author LiZheng
 * @date 2023年10月31日 下午4:28:47
 */

public class PairPrefixGroup
{
	List<PairPrefix> ppList = new ArrayList<>();
	PairPrefix lastActive = null;

	public void append(String q, String a)
	{
		append(q, a, false, false);
	}

	public void append(String q, String a, boolean firstOnly, boolean allowNoA)
	{
		PairPrefix pp = new PairPrefix(q, a, firstOnly, allowNoA);
		ppList.add(pp);
	}

	public List<StringPair> splitContentPairs(String input)
	{
		List<StringPair> sp = new ArrayList<>();

		for (PairPrefix pp : ppList)
		{
			lastActive = pp;
			sp = pp.splitContentPairs(input);
			if (!sp.isEmpty())
				return sp;
		}

		return sp;
	}

	public List<StringPair> splitByParagraph(String input)
	{
		List<StringPair> sp = new ArrayList<>();

		for (PairPrefix pp : ppList)
		{
			lastActive = pp;
			sp = pp.splitByParagraph(input);
			if (!sp.isEmpty())
				return sp;
		}

		return sp;
	}

	public int mode()
	{
		return lastActive == null ? -1 : lastActive.mode;
	}
}
